package com.hkts.naturalgas.curvesettings.controller;


import com.hkts.naturalgas.curvesettings.vo.CurveDTo;
import com.hkts.naturalgas.curvesettings.vo.CurveVo;
import org.springframework.web.bind.annotation.*;
import com.hkts.naturalgas.utils.CustomPageUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hkts.naturalgas.utils.Result;
import com.hkts.naturalgas.utils.ResultUtil;
import com.alibaba.fastjson.JSON;
import org.springframework.ui.Model;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMethod;


import com.hkts.naturalgas.curvesettings.service.ICurveSettingsService;
import com.hkts.naturalgas.curvesettings.entity.CurveSettings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * @author yck
 * @since 2021-10-11
 */
@RestController
@RequestMapping("/instrumentdata/curveSettings")
public class CurveSettingsController {
    private final Logger logger = LoggerFactory.getLogger(CurveSettingsController.class);

    @Autowired
    public ICurveSettingsService iCurveSettingsService;

    /**
     * 分页查询数据
     *
     * @param page          分页信息
     * @param curveSettings 查询条件
     * @return
     */
    @ResponseBody
    @GetMapping("/getCurveSettingsPageList")
    public Result<Object> getHontUserList(Page<CurveSettings> page, CurveSettings curveSettings) {
        return ResultUtil.data(CustomPageUtils.getCustomPage(iCurveSettingsService.selectPage(page, curveSettings)));
    }

    /**
     * 保存和修改公用的
     *
     * @param curveSettings 传递的实体
     * @return saveOrUpdate
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/curveSettingsSave")
    public Result<Object> curveSettingsSave(CurveSettings curveSettings) {
        iCurveSettingsService.saveOrUpdate(curveSettings);
        return ResultUtil.success("保存成功");
    }

    /**
     * 根据id获取对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/curveSettingsGetById")
    public Result<Object> curveSettingsGetById(String id) {
        CurveSettings byId = iCurveSettingsService.getById(id);
        return ResultUtil.data(byId);
    }

    /**
     * 根据id删除对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/curveSettingsDelete")
    public Result<Object> hontUserDelete(String id) {
        iCurveSettingsService.removeById(id);
        return ResultUtil.success("删除成功");
    }

    /**
     * 批量删除对象
     *
     * @param item 实体集合ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/curveSettingsBatchDelete")
    public Result<Object> deleteBatchIds(String item) {
        List<String> ids = (List<String>) JSON.parse(item);
        iCurveSettingsService.removeByIds(ids);
        return ResultUtil.success("删除成功");
    }

    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/curveSettingsGetByCurveId")
    public Result<Object> curveSettingsGetByCurveId(String curveId) {
        Map<String, Object> curveData = iCurveSettingsService.getCurveData(curveId);
        return ResultUtil.data(curveData);
    }

    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/updateCurveSettingsByCurveId")
    public Result<Object> updateCurveSettingsByCurveId(@RequestBody CurveVo curveVos) {
        Result<Object> result=  iCurveSettingsService.updateCurve(curveVos);
        return result;
    }




}
